# Maintainer: Massimiliano Torromeo <massimiliano.torromeo@gmail.com>

pkgname=nginx-mod-brotli
epoch=1
pkgver=1.0.0rc
pkgrel=7

_modname="ngx_${pkgname#nginx-mod-}"

pkgdesc="Brotli compression filter module for nginx"
arch=('loong64' 'x86_64')
depends=("nginx" 'brotli')
makedepends=("nginx-src")
url="https://github.com/google/ngx_brotli"
license=('CUSTOM')

source=(
	https://github.com/google/$_modname/archive/v$pkgver/$_modname-$pkgver.tar.gz
)
validpgpkeys=(B0F4253373F8F6F510D42178520A9993A1C052F8) # Maxim Dounin <mdounin@mdounin.ru>
sha256sums=('c85cdcfd76703c95aa4204ee4c2e619aa5b075cac18f428202f65552104add3b')

prepare() {
	mkdir -p build
	cd build
	ln -sf /usr/src/nginx/auto
	ln -sf /usr/src/nginx/src

	cd "$srcdir"/$_modname-$pkgver
	sed 's@/usr/local@/usr@' -i config
}

build() {
	cd build
	/usr/src/nginx/configure --with-compat --add-dynamic-module=../$_modname-$pkgver
	make modules
}

package() {
	install -Dm644 "$srcdir"/$_modname-$pkgver/LICENSE \
	               "$pkgdir"/usr/share/licenses/$pkgname/LICENSE

	cd build/objs
	for mod in ngx_*.so; do
		install -Dm755 $mod "$pkgdir"/usr/lib/nginx/modules/$mod
	done
}
